package sagroup.pdlime;

import java.net.UnknownHostException;


import lights.adapters.Field;
import lights.adapters.Tuple;
import lime2.CountAndDispReactionListener;
import lime2.Location;
import lime2.PolicyException;

public class ReplicaNode {
	private static final int HTTP_PORT = 8093;
	private static final int PORT = 1993;
	static String FRPrefix = "tsToBeFullReplicated";
	static String RCPrefix = "tsToBeReadCached";
	static int totalToBeOut = 5;

	public static void main(String[] args) throws UnknownHostException,
			PolicyException {
		// a node whose tuples will be full replicated by another node.
		NodePartinTesting srcNode = new NodePartinTesting(PORT, HTTP_PORT);

		srcNode.piccoSpace.changeReplicationPolicy(new TupleType(FRPrefix),
				PDPolicy.FR);
		srcNode.piccoSpace.changeUpdatePolicy(new TupleType(FRPrefix),
				PDPolicy.MASTER);
		srcNode.piccoSpace.changeReplicationPolicy(new TupleType(RCPrefix),
				PDPolicy.RC);
		srcNode.piccoSpace.changeUpdatePolicy(new TupleType(RCPrefix),
				PDPolicy.MASTER);

		TVRLimeTemplate p = new TVRLimeTemplate(null, Location.HERE,
				Location.HERE, new TupleType(FRPrefix), null, null,
				Location.HERE, Location.HERE, Boolean.FALSE,
				new Tuple().add(new Field().setType(String.class)));
		srcNode.piccoSpace
				.addStrongReaction(new VersionedReaction[] { new VersionedReaction(
						VersionedReaction.ONCEPERTUPLE, p,
						new CountAndDispReactionListener()) });

		srcNode.piccoSpace.out(new TupleType(FRPrefix), new Tuple()
				.add(new Field().setValue(FRPrefix + "self")));

	}
}
